﻿#include "stringutil.h"

QString StringUtil::ByteArrayToString2(QByteArray array)
{
    QString binaryString;

    for (char byte : array)
    {
        for(int i = 7; i >= 0; --i)
        {
            binaryString.append((byte & (1 << i)) ? '1' : '0');
        }

        binaryString.append('\n');
    }

    return binaryString;
}

QString StringUtil::ByteArrayToString10(QByteArray array)
{
    QString decimalString;

    for (char byte : array)
    {
        decimalString.append(QString::number(static_cast<unsigned char>(byte)));
        decimalString.append('\n');
    }

    return decimalString;
}

QString StringUtil::ByteArrayToString16(QByteArray array)
{
    QString hexString;

    for (char byte : array)
    {
        hexString.append("0x" + QString::number(static_cast<unsigned char>(byte), 16).rightJustified(2, '0').toUpper());
        hexString.append('\n');
    }

    return hexString;
}
